package com.suixun.controller;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.web.bind.annotation.*;

import com.suixun.controller.base.BaseController;
import com.suixun.domain.Banner;
import com.suixun.service.BannerService;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jacky
 * @since 2018-01-08
 */
@RestController
@RequestMapping("/banner")
public class BannerController extends BaseController {

    @Resource
    private BannerService bannerService;
    @Resource
    private SqlSessionFactory sqlSessionFactory;

    /**
     * 功能描述: 查询banner列表
     *
     * @param index
     * @param type
     * @return
     */
    @GetMapping("/listBanners/{type}")
    public Object listBanners(Integer index, @PathVariable("type") Integer type) {
        return success(bannerService.listBanners(index, type));
    }

    /**
     * 功能描述: 查询指定banner
     *
     * @param index
     * @param type
     * @return
     */
    @GetMapping("/getBanner/{type}/{index}")
    public Object getBanner(@PathVariable("type") Integer type, @PathVariable("index") Integer index) {
        return success(bannerService.getBanner(index, type));
    }

    @PostMapping(value = "/add")
    public Object addBanner(Banner banner) {
        bannerService.insertBanner(banner);
        return success();
    }

    @PostMapping(value = "/update")
    public Object updateBanner(Banner banner) {
        bannerService.updateBanner(banner);
        return success();
    }

    @PostMapping(value = "/delete")
    public Object deleteBanner(String ids) {
        bannerService.delete(ids);
        return success();
    }

    @GetMapping(value = "/page/{page}/{size}")
    public Object pageBanner(@PathVariable("page") Integer page, @PathVariable("size") Integer size, Integer type,
                             Integer index, String title) {
        return success(bannerService.pageBanner(page, size, title, type, index));
    }
}
